package org.example.controller;

import com.github.pagehelper.PageInfo;
import org.example.entity.Psych;
import org.example.entity.User;
import org.example.service.PsychService;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsychController
 * @Description TODO
 * @Author lipeijin
 * @Date 2025年08月15日 下午6:28
 * @Version 1.0
 */
@RestController
@RequestMapping("Psych")
public class PsychController {
    @Autowired
    private PsychService psychService;
    @GetMapping
    public R getPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                     @RequestParam(required = false,defaultValue = "10") int PageSize){
        PageInfo<Psych> pageInfo = psychService.getPage(pageNum, PageSize);
        return R.ok(pageInfo);
    }
    @GetMapping("userId")
    public R getPageMore(@RequestParam(required = false,defaultValue = "1") int pageNum,
                     @RequestParam(required = false,defaultValue = "10") int PageSize){
        PageInfo<Psych> pageInfo = psychService.getPageMore(pageNum, PageSize);
        return R.ok(pageInfo);
    }
    @GetMapping("userId/Time")
    public R getPageByTime(@RequestParam(required = false,defaultValue = "1") int pageNum,
                         @RequestParam(required = false,defaultValue = "10") int PageSize){
        PageInfo<Psych> pageInfo = psychService.getPageByTime(pageNum, PageSize);
        return R.ok(pageInfo);
    }
    @GetMapping("userId/Num")
    public R getPageByNum(@RequestParam(required = false,defaultValue = "1") int pageNum,
                         @RequestParam(required = false,defaultValue = "10") int PageSize){
        PageInfo<Psych> pageInfo = psychService.getPageByNum(pageNum, PageSize);
        return R.ok(pageInfo);
    }
    @PostMapping("add")
    public R addPsych(@RequestBody Psych psych){
        int i = psychService.addPsych(psych);
        if(i>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @PutMapping("{id}")
    public R updateReplyCount(@PathVariable("id") int id){
        int i = psychService.updateReplyCount(id);
        if(i>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }




}
